// pages/my/appointment-recordDetail/appointment-recordDetail.js
const controllers = require('../../controllers/ControllerMy').controller;
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    globalStype:'',
    goodsAgreeId: 0,
    detail: {},
    navlist: ['审核中', '待签到', '已完成', '已关闭'],
    imgurl: '',
    desc:'',
    shopId:''
  },
  //确认签到
  ok() {
    controllers.appointmentOk({
      shopId: app.globalData.shopId,
      goodsAgreeId: this.data.goodsAgreeId
    }).then(res => {
      console.log(res);
      wx.showToast({
        title: '签到成功',
        icon:'none'
      })
      //获取详情
      let shopId=this.data.shopId || app.globalData.shopId
      controllers.apponintmentDetail({
        shopId: shopId,
        goodsAgreeId: this.data.goodsAgreeId
      }).then(res => {
        console.log(res);
        this.setData({
          detail: res.data
        })
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({globalStype:app.globalData.globalStype})
    console.log(options);
    
    this.setData({
      imgurl:app.globalData.IMG_URL
    })
    if(options.shopId){
      this.setData({
        shopId:options.shopId
      })
      app.globalData.shopId = options.shopId;
      wx.setStorageSync('shopId', options.shopId);
    }
    //获取详情
    let shopId=options.shopId || app.globalData.shopId
    controllers.apponintmentDetail({
      shopId: shopId,
      goodsAgreeId: options.id
    }).then(res => {
      console.log(res);
      this.setData({
        detail: res.data,
        goodsAgreeId:options.id,
        desc:res.data.desc || ''
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // },
  backIndex(){
    let page=getCurrentPages()
    let shopId=this.data.shopId
    console.log(page.length)
    if(page.length<=1){
      wx.redirectTo({
        url: '/pages/Index/Index?shopId='+shopId,
      })
    }
  }
})